package com.gx.mxbbx.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gx.mxbbx.dao.DiseaseMapper;
import com.gx.mxbbx.po.Disease;
import com.gx.mxbbx.service.DiseaseService;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
@Transactional
public class DiseaseServiceImpl implements DiseaseService {
    @Autowired
    private DiseaseMapper diseaseMapper;

    public PageInfo<Disease> getdiseaseList(String fullName, Integer currentPage, Integer limit) {
        PageHelper.startPage(currentPage, limit);
        List<Disease> list = diseaseMapper.getdiseaseList(fullName);
        PageInfo<Disease> pageInfo = new PageInfo<Disease>(list);
        return pageInfo;
    }

    public void diseaseadd(Disease disease) {
        diseaseMapper.diseaseadd(disease);
    }

    public Disease diseaseopenEdit(Integer id) {
        Disease disease = diseaseMapper.diseaseopenEdit(id);
        return disease;
    }

    public void diseaseedit(Disease disease) {
        diseaseMapper.diseaseedit(disease);

    }

    public void diseasedelete(Integer id) {
        diseaseMapper.diseasedelete(id);
    }


    public XSSFWorkbook show(Integer id) {
        List<Disease> list = diseaseMapper.selectByExample(id);//查出数据库数据
        XSSFWorkbook wb = new XSSFWorkbook();
        Sheet sheet = wb.createSheet("Goods");//创建一张表
        org.apache.poi.ss.usermodel.Row titleRow = sheet.createRow(0);//创建第一行，起始为0
        titleRow.createCell(0).setCellValue("id");//第一列
        titleRow.createCell(1).setCellValue("农合证号");
        titleRow.createCell(2).setCellValue("慢病证号");
        titleRow.createCell(3).setCellValue("身份证号");
        titleRow.createCell(4).setCellValue("疾病名称");
        titleRow.createCell(5).setCellValue("姓名");
        titleRow.createCell(6).setCellValue("性别");
        titleRow.createCell(7).setCellValue("年龄");
        titleRow.createCell(8).setCellValue("电话");
        titleRow.createCell(9).setCellValue("起始时间");
        titleRow.createCell(10).setCellValue("终止时间");
        int cell = 1;
        for (Disease leave : list) {
            Row row = sheet.createRow(cell);//从第二行开始保存数据
            row.createCell(0).setCellValue(cell);
            row.createCell(1).setCellValue(leave.getPeasantId());//将数据库的数据遍历出来
            row.createCell(2).setCellValue(leave.getDiseaseId());
            row.createCell(3).setCellValue(leave.getIdentityCard());
            row.createCell(4).setCellValue(leave.getSortName());
            row.createCell(5).setCellValue(leave.getFullName());
            row.createCell(6).setCellValue(leave.getSex());
            row.createCell(7).setCellValue(leave.getYear());
            row.createCell(8).setCellValue(leave.getTelephone());
            row.createCell(9).setCellValue(leave.getCreateTime());
            row.createCell(10).setCellValue(leave.getUpdateTime());
            cell++;
        }
        return wb;
    }


}
